package com.study.userserviceprovider.controller;

import com.study.api.Result;
import com.study.exception.BizException;
import com.study.userserviceprovider.biz.AbstarctLogin;
import com.study.userserviceprovider.biz.Login;
import com.study.userserviceprovider.dto.AuthLoginDto;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description：登录处理
 * @author：李军荣
 * @date: 2020/12/28 10:41
 */
@RestController
public class LoginController {

    @PostMapping("login")
    public Result loginAuth(@RequestBody @Validated AuthLoginDto authLoginDto, BindingResult bindingResult){
        authLoginDto.validData(bindingResult);
        Login login = AbstarctLogin.loginMap.get(authLoginDto.getLoginType());
        if(null == login){
            throw new BizException("暂不支持此种登录方式");
        }
        return login.doLogin(authLoginDto);
    }
}
